package com.design.behavior.observer.cainiao;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: design
 * @Package: com.design.behavior.observer.cainiao
 * @ClassName: Subject
 * @Author: shenaiguo
 * @Description:创建 Subject 类。
 * @Date: 2020/11/23 0023 20:25
 */
// 第一步
public class Subject {

    private List<Observer> observers
            = new ArrayList<Observer>();
    private int state;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(Observer observer){
        observers.add(observer);
    }

    public void notifyAllObservers(){
        for (Observer observer : observers) {
            observer.update();
        }
    }
}
